package com.ssm.tag;

import java.io.IOException;

import javax.servlet.ServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;


/**
 * SSM定义标签用于页面模板占位
 * @author WWT<245108903@qq.com>
 * @version 2016/1/20
 * */

public class BlockTag extends BodyTagSupport {

	private static final long serialVersionUID = 1L;

	private static final String PREFIX = "SSMTAG_";
	
	private String name;
	
	
	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	@Override
	public int doEndTag() throws JspException {
		// TODO Auto-generated method stub

		ServletRequest request=pageContext.getRequest();
		String oldBodyContext=getBodyContent()==null?"":getBodyContent().getString();
		String newBodyContext=request.getAttribute(PREFIX+name).toString();
		newBodyContext=newBodyContext==""?oldBodyContext:newBodyContext;
		try {
			pageContext.getOut().write(newBodyContext);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return super.doEndTag();
	}
	
	

}
